package com.zhou.common.mybatis.template.shiro.config.shiro.exception;

import com.zhou.common.lib.exception.BaseExceptionHandler;
import com.zhou.common.lib.model.Response;
import com.zhou.common.lib.properties.BaseProperties;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ShiroExceptionHandler extends BaseExceptionHandler {

    public ShiroExceptionHandler(BaseProperties baseProperties) {
        super(baseProperties);
    }

    @ExceptionHandler(UnauthorizedException.class)
    public Response handleException(UnauthorizedException e) {
        log.error("", e);
        if (baseProperties != null && baseProperties.getPrintExceptionDetail()) {
            return new Response(999, e.getMessage());
        }
        return new Response(999, "服务器忙，请稍后重试");
    }
}
